﻿// DialogCodeType.cpp: 实现文件
//

#include "stdafx.h"
#include "SKEYRmt.h"
#include "DialogCodeType.h"
#include "afxdialogex.h"
#include "..\\SKEYWeb\\DPIForm.h"


// CDialogCodeType 对话框

IMPLEMENT_DYNAMIC(CDialogCodeType, CDialogEx)

CDialogCodeType::CDialogCodeType(int type, CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_CODETYPE, pParent), m_codeType(type)
{

}

CDialogCodeType::~CDialogCodeType()
{
}

void CDialogCodeType::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_CHECK0, m_Check0);
	DDX_Control(pDX, IDC_CHECK1, m_Check1);
	DDX_Control(pDX, IDC_CHECK2, m_Check2);
	DDX_Control(pDX, IDOK, m_OK);
}


BEGIN_MESSAGE_MAP(CDialogCodeType, CDialogEx)
	ON_BN_CLICKED(IDC_CHECK0, &CDialogCodeType::OnBnClickedCheck0)
	ON_BN_CLICKED(IDC_CHECK1, &CDialogCodeType::OnBnClickedCheck1)
	ON_BN_CLICKED(IDC_CHECK2, &CDialogCodeType::OnBnClickedCheck2)
END_MESSAGE_MAP()


// CDialogCodeType 消息处理程序
void CDialogCodeType::OnBnClickedCheck0()
{
	m_OK.EnableWindow(getCodeType() ? TRUE : FALSE);
}
void CDialogCodeType::OnBnClickedCheck1()
{
	m_OK.EnableWindow(getCodeType() ? TRUE : FALSE);
}
void CDialogCodeType::OnBnClickedCheck2()
{
	m_OK.EnableWindow(getCodeType() ? TRUE : FALSE);
}

int CDialogCodeType::getCodeType()
{
	int type = 0;
	if (m_Check0.GetCheck()) type |= 0x1;
	if (m_Check1.GetCheck()) type |= 0x2;
	if (m_Check2.GetCheck()) type |= 0x4;
	return type;
}

BOOL CDialogCodeType::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	CDPIForm(this, 12, 12)
		.ctrl(IDC_GROUP0).top().left()
		.ctrl(m_Check0).SizeToContent().groupLeft(IDC_GROUP0).groupTop(IDC_GROUP0)
		.ctrl(m_Check1).SizeToContent().groupLeft(IDC_GROUP0).below(m_Check0, 10)
		.ctrl(m_Check2).SizeToContent().groupLeft(IDC_GROUP0).below(m_Check1, 10)
		.ctrl(IDC_GROUP0).resizeGroup(&m_Check0, &m_Check2)
		.ctrl(m_OK).after(IDC_GROUP0, 20).alignTop(IDC_GROUP0)
		.ctrl(IDCANCEL).alignWidth(m_OK).below(m_OK, 20)
		.resizeWindow(&m_OK, IDC_GROUP0);
	m_Check0.SetCheck((m_codeType & 0x1) ? 1 : 0);
	m_Check1.SetCheck((m_codeType & 0x2) ? 1 : 0);
	m_Check2.SetCheck((m_codeType & 0x4) ? 1 : 0);
	m_OK.EnableWindow(getCodeType() ? TRUE : FALSE);
	m_codeType = 0;
	return TRUE;
}

void CDialogCodeType::OnOK()
{
	m_codeType = getCodeType(); if (!m_codeType) return;
	CDialogEx::OnOK();
}
